//
//  DiagnosisCell.m
//  Router
//
//  Created by gejiangs on 15/10/15.
//  Copyright © 2015年 dc. All rights reserved.
//

#import "DiagnosisCell.h"

@interface DiagnosisCell ()

@property (nonatomic, strong)   UILabel *titleLabel;
@property (nonatomic, strong)   UILabel *stateLabel;
@property (nonatomic, strong)   UILabel *tipLabel;

@end

@implementation DiagnosisCell

- (void)awakeFromNib {
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)initUI
{
    self.backgroundView = [UIView new];
    self.backgroundColor = [UIColor clearColor];
    
    UIView *boxView = [[UIView alloc] init];
    boxView.layer.borderColor = COLOR_BASE.CGColor;
    boxView.layer.borderWidth = 1.f;
    boxView.layer.cornerRadius = 10.f;
    [self.contentView addSubview:boxView];
    [boxView makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
        make.left.offset(20);
        make.right.offset(-20);
    }];
    
    self.titleLabel = [boxView addLabelWithText:@"6000000" font:[UIFont systemFontOfSize:18] color:COLOR_BASE];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    [_titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.offset(5);
    }];
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = COLOR_BASE;
    [boxView addSubview:lineView];
    [lineView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(30);
        make.height.offset(1);
    }];
    
    
    self.stateLabel = [boxView addLabelWithText:@"连接状态：非常好" font:[UIFont systemFontOfSize:18] color:COLOR_BASE];
    _stateLabel.textAlignment = NSTextAlignmentCenter;
    _stateLabel.adjustsFontSizeToFitWidth = YES;
    [_stateLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView.bottom).offset(10);
        make.left.equalTo(boxView.left);
        make.right.equalTo(boxView.right);
    }];
    
    
    self.tipLabel = [boxView addLabelWithText:@"非常适合" font:[UIFont systemFontOfSize:16] color:[UIColor grayColor]];
    _tipLabel.textAlignment = NSTextAlignmentCenter;
    [_tipLabel makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self.contentView);
        make.top.equalTo(_stateLabel.bottom).offset(5);
        make.left.equalTo(boxView.left);
        make.right.equalTo(boxView.right);
    }];

    self.tipLabel.adjustsFontSizeToFitWidth = YES;
}




- (void)setModel:(StationModel *)model
{
    _model = model;
    self.titleLabel.text = model.alias;
    NSString *status;
    NSString *message;
    UIColor *status_color;
    if (model.link_quality >= 90) {
        status = @"连接状态：非常好";
        message = @"子WIFI插在这个电源口上再合适不过了";
        status_color = COLOR_BASE;
    }
    else if (model.link_quality >=60 && model.link_quality < 90)
    {
        status = @"连接状态：一般";
        message = @"子WIFI与母猫之间的通信可能会收到电路干扰";
        status_color = [UIColor colorWithRed:255.0/255 green:234.0/255 blue:0/255.0 alpha:1.0];
    }
    else{
        status = @"连接状态：信号低,子WIFI未插上电?";
        message = @"建议将子猫换一个电源插口重试一下";
        status_color = [UIColor colorWithRed:214.0/255 green:27.0/255 blue:18/255.0 alpha:1.0];
    }
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:status];
    [str addAttribute:NSForegroundColorAttributeName value:status_color range:NSMakeRange(5,status.length-5)];
    self.stateLabel.attributedText = str;
    //self.stateLabel.text = status;
    self.tipLabel.text = message;

}
@end
